//

// (  )
//

package com.tools.acceleratecore.xlib.tool.impl;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import com.tools.acceleratecore.xlib.XLibFactory;
import com.tools.acceleratecore.xlib.tool.intf.IScreenObserver;
import com.tools.acceleratecore.xlib.tool.intf.IScreenObserverListener;
import com.tools.acceleratecore.xlib.xlib.impl.XObserver;
import java.util.Iterator;

public class ScreenObserver extends XObserver<IScreenObserverListener> implements IScreenObserver {
    private Context mContext = null;
    private boolean mInited = false;
    private BroadcastReceiver mBR = null;

    public ScreenObserver() {
        this.mContext = XLibFactory.getApplication();
        this._init();
    }

    private void _init() {
        this.mBR = new BroadcastReceiver() {
            public void onReceive(Context context, Intent intent) {
                IScreenObserverListener listener;
                Iterator var5;
                if (intent.getAction().equals("android.intent.action.SCREEN_ON")) {
                    synchronized(ScreenObserver.this.mListListener) {
                        var5 = ScreenObserver.this.getListListener().iterator();

                        while(var5.hasNext()) {
                            listener = (IScreenObserverListener)var5.next();
                            listener.onScreenOn();
                        }
                    }
                } else if (intent.getAction().equals("android.intent.action.SCREEN_OFF")) {
                    synchronized(ScreenObserver.this.mListListener) {
                        var5 = ScreenObserver.this.getListListener().iterator();

                        while(var5.hasNext()) {
                            listener = (IScreenObserverListener)var5.next();
                            listener.onScreenOff();
                        }
                    }
                } else if (intent.getAction().equals("android.intent.action.USER_PRESENT")) {
                    synchronized(ScreenObserver.this.mListListener) {
                        var5 = ScreenObserver.this.getListListener().iterator();

                        while(var5.hasNext()) {
                            listener = (IScreenObserverListener)var5.next();
                            listener.onUserPresent();
                        }
                    }
                }

            }
        };
    }

    public boolean startListen() {
        if (this.mInited) {
            return false;
        } else {
            this.mInited = true;
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.intent.action.SCREEN_ON");
            intentFilter.addAction("android.intent.action.SCREEN_OFF");
            intentFilter.addAction("android.intent.action.USER_PRESENT");
            this.mContext.registerReceiver(this.mBR, intentFilter);
            return true;
        }
    }

    public void stopListen() {
        if (this.mInited) {
            this.mInited = false;
            this.mContext.unregisterReceiver(this.mBR);
        }
    }
}
